package ar.com.jendrix.common.web.util;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import ar.com.jendrix.common.persistence.entity.dto.BaseEntityDTO;
import ar.com.jendrix.common.persistence.entity.dto.Descriptible;
import ar.com.jendrix.common.util.Comparator;

public final class SelectItemUtil {

	public static final List<SelectItem> getEmptyList() {
		return new ArrayList<SelectItem>();
	}

	public static final <DTO extends BaseEntityDTO> List<SelectItem> getSelectItemList(List<DTO> dtoList) {
		final List<SelectItem> s = new ArrayList<SelectItem>();

		if (!Comparator.isEmpty(dtoList)) {
			for (Descriptible dto : dtoList) {
				s.add(new SelectItem(dto.getId(), dto.getDescription()));
			}
		}
		return s;
	}

	public static final String getDescription(List<SelectItem> selectItemList, Long id) {
		String description = "";
		for (SelectItem s : selectItemList) {
			if (s.getValue().equals(id)) {
				description = s.getLabel();
				break;
			}
		}
		return description;
	}
}